home *** CD-ROM | disk | FTP | other *** search
- /* Display the application's about dialog.
- 93/12/17 aih - version string is read from vers resource
- 93/12/16 aih - window's position is saved in prefs
- 93/03/12 aih - created */
-
- #include <stdio.h>
- #include "AboutLib.h"
- #include "DialogLib.h"
- #include "MemoryLib.h"
- #include "MenuLib.h"
- #include "PreferencesLib.h"
- #include "ResourceConstantsLib.h"
- #include "ResourceLib.h"
-
- #define iVersionText (1) /* item in dialog for displaying version string */
-
- static DialogPtr gAbout;
-
- /* get short version string from 'vers' resource */
- static void GetVersion(CStr31 str)
- {
- Ptr p = NULL;
- short n = 0;
- struct vers {
- char ver1;
- char ver2;
- char level;
- char stage;
- short region;
- };
-
- p = *ResGet('vers', RLVERS_APPLICATION) + sizeof(struct vers);
- n = (*p < sizeof(CStr31) ? *p : sizeof(CStr31) - 1);
- BlockMove(p + 1, str, n);
- str[n] = 0;
- }
-
- /* open the about dialog */
- void AboutOpen(void)
- {
- CStr255 fmt, str;
- CStr31 vers;
- volatile DialogPtr about = NULL;
-
- TRY {
- if (gAbout)
- WinSelect(gAbout);
- else {
- about = DlgBegin(RLD_ABOUT);
- DlgText(about, iVersionText, fmt);
- GetVersion(vers);
- sprintf(str, fmt, vers);
- DlgTextSet(about, iVersionText, str);
- DlgCenter(about);
- WinRegister(about, about, AboutEventTable());
- WinZoomRestore(about, PrefsFile(), PREFS_ABOUT_POSITION);
- WinShow(about);
- gAbout = about;
- about = NULL;
- }
- } CATCH {
- DlgEnd(about);
- } ENDTRY;
- }
-
- /* close the about dialog */
- void AboutClose(void)
- {
- if (gAbout) {
- WinZoomSave(gAbout, PrefsFile(), PREFS_ABOUT_POSITION);
- WinUnregister(gAbout, gAbout);
- DlgEnd(gAbout);
- gAbout = NULL;
- }
- }
-
- /* true if about dialog has focus */
- static Boolean AboutHasFocus(void)
- {
- return(gAbout && WinHasFocus(gAbout));
- }
-
- /* adjust about menu item */
- void AboutAdjustMenu(void)
- {
- if (MemWarning() < MEM_WARNING_VERY_LOW) {
- if (! WinModalHasFocus()) MenuCmdEnable(CMD_ABOUT);
- MenuCmdCheck(CMD_ABOUT, AboutHasFocus());
- }
- if (AboutHasFocus())
- MenuCmdEnable(CMD_CLOSE);
- }
-
- Boolean AboutMenu(const MenuPickType *pick)
- {
- Boolean handled = false;
-
- switch (pick->cmd) {
- case CMD_ABOUT:
- AboutOpen();
- handled = true;
- break;
- case CMD_CLOSE:
- if (AboutHasFocus()) {
- AboutClose();
- handled = true;
- }
- break;
- }
- return(handled);
- }
-
- void AboutMemoryLow(void)
- {
- if (MemWarning() >= MEM_WARNING_VERY_LOW)
- AboutClose();
- }
-